package com.github.rxyor.common.core.exception;

import com.github.rxyor.common.core.enums.CoreExCodeEnum;
import com.github.rxyor.common.core.enums.KeyValue;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019/10/8 周二 11:19:00
 * @since 1.0.0
 */
@EqualsAndHashCode(callSuper = false)
@ToString(callSuper = true)
public class CoreException extends RuntimeException {

    private static final long serialVersionUID = 2349859127345341539L;

    @Getter
    private Integer code;

    @Getter
    private String msg;

    public CoreException() {
        this(CoreExCodeEnum.FAIL.getCode(), CoreExCodeEnum.FAIL.getDesc());
    }

    public CoreException(String msg) {
        this(CoreExCodeEnum.FAIL.getCode(), msg);
    }

    public CoreException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public CoreException(String msg, Throwable cause) {
        super(msg, cause);
        this.code = CoreExCodeEnum.FAIL.getCode();
        this.msg = msg;
    }

    public CoreException(Integer code, String msg, Throwable cause) {
        super(msg, cause);
        this.code = code;
        this.msg = msg;
    }

    public CoreException(Throwable e) {
        super(e);
        this.code = CoreExCodeEnum.FAIL.getCode();
        this.msg = e.getMessage();
    }

    public CoreException(KeyValue<? extends Integer> kv) {
        this(kv.getCode(), kv.getDesc());
        this.code = kv.getCode();
        this.msg = kv.getDesc();
    }

    public CoreException(KeyValue<? extends Integer> kv, String msg) {
        this(kv.getCode(), msg);
        this.code = kv.getCode();
        this.msg = msg;
    }

    public CoreException(KeyValue<? extends Integer> kv,String msg, Throwable cause) {
        this(kv.getCode(), kv.getDesc(),cause);
        this.code = kv.getCode();
        this.msg = msg;
    }

    public CoreException(KeyValue<? extends Integer> kv, Throwable cause) {
        this(kv.getCode(), kv.getDesc());
        this.code = kv.getCode();
        this.msg = kv.getDesc();
    }
}
